package com.yanqu.road.server.cmd.activity.feast;

import com.yanqu.road.entity.activity.feast.config.ShanHeFeastConfig;
import com.yanqu.road.entity.activity.feast.data.CrossFeastPvpData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.feast.CrossFeastMgr;
import com.yanqu.road.server.manager.activity.feast.activity.CrossFeastActivity;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

//@Cmd(code = CrossProtocol.C_CROSS_SHAN_HE_FEAST_LEAVE_PLACE, desc = "离开房间")
public class CrossFeastLeavePlaceCmd extends CrossCommand {

    private int activityId;

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ShanHeFeastProto.CrossFeastLeavePlaceReqMsg reqMsg = ShanHeFeastProto.CrossFeastLeavePlaceReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossFeastActivity activity = CrossFeastMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_ACTIVITY_NOT_FOUND;
            return;
        }
        ShanHeFeastConfig config = activity.getConfig();
        if (config == null) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_CONFIG_NOT_FOUND;
            return;
        }
        CrossFeastPvpData pvpData = activity.getCrossFeastPvpData();
        if (pvpData == null || !activity.isBattleTime()) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_PVP_NO_OPERATE_TIME;
            return;
        }
//        ret = activity.leavePlaceByCmd(packet.getPlayerId());
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            ShanHeFeastProto.FeastLeavePlaceRespMsg.Builder respMsg = ShanHeFeastProto.FeastLeavePlaceRespMsg.newBuilder();
            respMsg.setRet(ret);
//            MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(Protocol.U_SHAN_HE_FEAST_LEAVE_PLACE, respMsg));
        }
    }
}
